package com.itfox.day06;


import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;


@WebServlet("/demo01")
public class servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getMethod();
        if("GET".equals(method)){
            System.out.println(req.getQueryString());
        }else {
            String name = req.getParameter("name");
            String s = new String(name.getBytes("ISO-8859-1"), "UTF-8");
            System.out.println(s);
            resp.setContentType("text/html;charset=utf-8");
            resp.getWriter().print("<h1>你好<h1/>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
